package comframe.jdbc.sql.datasource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnFactory {
	
	private static ConnFactory factory;
	
	private ConnFactory(){}

	public static ConnFactory getFactory(){
		if(factory == null)
			factory = new ConnFactory ();
		return factory;
	}
	
	public Connection getConn(Config config) throws ClassNotFoundException, SQLException{
		Class.forName(config.getClassName());
		return DriverManager.getConnection(config.getUrl(), config.getUserName(),config.getPassword());
	}
	
	public Connection getConn(Config config,String userName,String password) throws ClassNotFoundException, SQLException{
		Class.forName(config.getClassName());
		return DriverManager.getConnection(config.getUrl(),userName,password);
	}
	public Connection getConn(String className,String url,String userName,String password) throws ClassNotFoundException, SQLException{
		Class.forName(className);
		return DriverManager.getConnection(url,userName,password);
	}
}
